home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / usefacet.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  7.8 KB  |  168 lines

  1. #ifndef __STD_USEFACET__
  2. #define __STD_USEFACET__
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * usefacet - Declarations for the Standard Library facet access functions
  8.  *            and for the convenience functions (isalpha etc.)
  9.  *
  10.  *
  11.  ***************************************************************************
  12.  *
  13.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  14.  * ALL RIGHTS RESERVED *
  15.  * The software and information contained herein are proprietary to, and
  16.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  17.  * intends to preserve as trade secrets such software and information.
  18.  * This software is furnished pursuant to a written license agreement and
  19.  * may be used, copied, transmitted, and stored only in accordance with
  20.  * the terms of such license and with the inclusion of the above copyright
  21.  * notice.  This software and information or any other copies thereof may
  22.  * not be provided or otherwise made available to any other person.
  23.  *
  24.  * Notwithstanding any other lease or license that may pertain to, or
  25.  * accompany the delivery of, this computer software and information, the
  26.  * rights of the Government regarding its use, reproduction and disclosure
  27.  * are as set forth in Section 52.227-19 of the FARS Computer
  28.  * Software-Restricted Rights clause.
  29.  *
  30.  * Use, duplication, or disclosure by the Government is subject to
  31.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  32.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  33.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  34.  * P.O. Box 2328, Corvallis, Oregon 97339.
  35.  *
  36.  * This computer software and information is distributed with "restricted
  37.  * rights."  Use, duplication or disclosure is subject to restrictions as
  38.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  39.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  40.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  41.  * then the "Alternate III" clause applies.
  42.  *
  43.  **************************************************************************/
  44.  
  45. #ifndef __STD_RWLOCALE__
  46. #include <rw/rwlocale>
  47. #endif
  48.  
  49. #ifndef _RWSTD_NO_NAMESPACE
  50. namespace std {
  51. #endif
  52.  
  53. // Template use_facet<Facet>(loc) returns a reference to a facet.  Its result
  54. // is guaranteed by locale's value semantics to last at least as long as the
  55. // locale or any copy of the locale it came from.
  56.  
  57. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  58. #define _RWSTD_SELECT_FACET
  59. #else
  60. #define _RWSTD_SELECT_FACET ,Facet*
  61. #endif
  62.  
  63. template <class Facet>
  64. inline const Facet & _RWSTDExport use_facet (const locale &loc _RWSTD_SELECT_FACET)
  65. {
  66.   // Ensure that Facet has a static member named id, and (via cast) that it is
  67.   // of type locale::id, and obtain from it (via size_t conversion operator)
  68.   // the private numeric index associated with type Facet for this run.
  69.   size_t i=(const locale::id&) Facet::id;
  70.  
  71.   // Get pointer to facet from locale.
  72.   const __RWSTD::facet_imp *f=loc.get_facet(i);
  73.  
  74.   // If facet is not _EXPLICITly present in locale yet, use private function
  75.   // locale::make__EXPLICIT to construct it or retrieve it from a cache, and
  76.   // install it in the locale.  This function can throw bad_cast or other
  77.   // exceptions.
  78.   if (!f)
  79.     f=loc.make__EXPLICIT(Facet::id,Facet::ok_implicit_,Facet::facet_cat_,
  80.         __RWSTD::facet_maker<Facet>::maker_func);
  81.  
  82.   return _RWSTD_STATIC_CAST(const Facet&,*f);
  83. }
  84.  
  85. // Function has_facet<Facet>(loc) simply reports whether a locale implements a
  86. // particular facet.  If has_facet<facet>(loc) is false, use_facet<facet>(loc)
  87. // would throw an exception.
  88.  
  89. template <class Facet>
  90. inline bool has_facet (const locale &loc _RWSTD_SELECT_FACET)
  91.     _RWSTD_THROW_SPEC_NULL
  92. {
  93.   size_t ix = (const locale::id&) Facet::id;  // verify is a locale::id.
  94.   return loc.imp_->get_facet(ix) != NULL || Facet::ok_implicit_;
  95. }
  96.  
  97. // convenience interfaces: is*(char)
  98.  
  99. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  100.  
  101. template <class charT> inline bool isspace(charT c, const locale& loc)
  102.   { typedef ctype<charT> idiot; return use_facet<idiot>(loc).is(ctype_base::space, c); }
  103. template <class charT> inline bool isprint(charT c, const locale& loc)
  104.   { return use_facet<ctype<charT> >(loc).is(ctype_base::print, c); }
  105. template <class charT> inline bool iscntrl(charT c, const locale& loc)
  106.   { return use_facet<ctype<charT> >(loc).is(ctype_base::cntrl, c); }
  107. template <class charT> inline bool isupper(charT c, const locale& loc)
  108.   { return use_facet<ctype<charT> >(loc).is(ctype_base::upper, c); }
  109. template <class charT> inline bool islower(charT c, const locale& loc)
  110.   { return use_facet<ctype<charT> >(loc).is(ctype_base::lower, c); }
  111. template <class charT> inline bool isalpha(charT c, const locale& loc)
  112.   { return use_facet<ctype<charT> >(loc).is(ctype_base::alpha, c); }
  113. template <class charT> inline bool isdigit(charT c, const locale& loc)
  114.   { return use_facet<ctype<charT> >(loc).is(ctype_base::digit, c); }
  115. template <class charT> inline bool ispunct(charT c, const locale& loc)
  116.   { return use_facet<ctype<charT> >(loc).is(ctype_base::punct, c); }
  117. template <class charT> inline bool isxdigit(charT c, const locale& loc)
  118.   { return use_facet<ctype<charT> >(loc).is(ctype_base::xdigit, c); }
  119. template <class charT> inline bool isalnum(charT c, const locale& loc)
  120.   { return use_facet<ctype<charT> >(loc).is(ctype_base::alnum, c); }
  121. template <class charT> inline bool isgraph(charT c, const locale& loc)
  122.   { return use_facet<ctype<charT> >(loc).is(ctype_base::graph, c); }
  123.  
  124. template <class charT> inline charT toupper(charT c, const locale& loc)
  125.   { return use_facet<ctype<charT> >(loc).toupper(c); }
  126. template <class charT> inline charT tolower(charT c, const locale& loc)
  127.   { return use_facet<ctype<charT> >(loc).tolower(c); }
  128.  
  129. #else
  130.  
  131. template <class charT> inline bool isspace(charT c, const locale& loc)
  132.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::space, c); }
  133. template <class charT> inline bool isprint(charT c, const locale& loc)
  134.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::print, c); }
  135. template <class charT> inline bool iscntrl(charT c, const locale& loc)
  136.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::cntrl, c); }
  137. template <class charT> inline bool isupper(charT c, const locale& loc)
  138.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::upper, c); }
  139. template <class charT> inline bool islower(charT c, const locale& loc)
  140.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::lower, c); }
  141. template <class charT> inline bool isalpha(charT c, const locale& loc)
  142.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::alpha, c); }
  143. template <class charT> inline bool isdigit(charT c, const locale& loc)
  144.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::digit, c); }
  145. template <class charT> inline bool ispunct(charT c, const locale& loc)
  146.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::punct, c); }
  147. template <class charT> inline bool isxdigit(charT c, const locale& loc)
  148.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::xdigit, c); }
  149. template <class charT> inline bool isalnum(charT c, const locale& loc)
  150.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::alnum, c); }
  151. template <class charT> inline bool isgraph(charT c, const locale& loc)
  152.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::graph, c); }
  153.  
  154. template <class charT> inline charT toupper(charT c, const locale& loc)
  155.   { return use_facet(loc,(ctype<charT>*)0).toupper(c); }
  156. template <class charT> inline charT tolower(charT c, const locale& loc)
  157.   { return use_facet(loc,(ctype<charT>*)0).tolower(c); }
  158.  
  159. #endif
  160.  
  161. #ifndef _RWSTD_NO_NAMESPACE
  162. } // namespace std
  163. #endif
  164.  
  165. #pragma option pop
  166. #endif //  __STD_USEFACET__
  167.  
  168.